import os
import configparser
import json

filepath = os.path.abspath(os.path.dirname(__file__))
base_config_path = os.path.join(filepath, 'base.ini')
base_cf = configparser.ConfigParser()
base_cf.read(base_config_path)

# 项目根目录
root_path = os.path.join(filepath, '..')

dev = 'dev'  # 测试环境
prod = 'prod'  # 正式环境
local = 'local'  # 本地环境
env = base_cf['base']['env']
cf = configparser.ConfigParser()
config_path = os.path.join(filepath, env, 'configs.ini')
cf.read(config_path)

mongodb_config = {
    "host": cf["mongodb"]["host"],
    "port": cf["mongodb"]["port"]
}

redis_config = {
    "host": cf["redis"]["host"],
    "port": cf["redis"]["port"]
}

mysql_config = {
    "user": cf["mysql"]["user"],
    "password": cf["mysql"]["password"],
    "database": cf["mysql"]["database"],
    "host": cf["mysql"]["host"],
    "port": int(cf["mysql"]["port"]),
    "charset": cf["mysql"]["charset"],
    "keepConnectionAlive": cf["mysql"]["keepConnectionAlive"],
    "minFreeConnections": int(cf["mysql"]["minFreeConnections"]),
    "maxConnections": int(cf["mysql"]["maxConnections"]),
}

userinfo_path = os.path.join(root_path, 'configs', 'userinfo.json')
with open(userinfo_path, 'r') as f:
    res = f.read()

userinfo = json.loads(res)

# 请求头
HEADERS = {
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
}
